<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@include file="/white/common/taglibs.jsp"%>
<%@include file="/white/common/common.jsp"%>

<html>
	<head>
		<script type="text/javascript">
		function validateDelete(){
            var check=document.getElementsByName("selectedIds");
            var a=false;
            for(var i=0;i <check.length;i++){
                if(check[i].checked==true){
                    a=true;
                    break;
                }
            }
            if(a){
                return confirm('你确定要删除?');
            }else{
                alert("请先择你要删除的内容!");
                return false;
            }
        }
        function addFromNode(workflowId, workflowNodeId){
            var nodeForm=document.getElementById("nodeForm");
            nodeForm.action="workflowAction-" + workflowId + "!addFromNode.action?workflowNodeId=" + workflowNodeId;
            nodeForm.submit();
            return true;
        }
        
        function addNextNode(workflowId, workflowNodeId){
            
            var nodeForm=document.getElementById("nodeForm");
            nodeForm.action="workflowAction-" + workflowId + "!addNextNode.action?workflowNodeId=" + workflowNodeId;
            nodeForm.submit();
            return true;
        }
        
        function removeFromNode(workflowId, workflowNodeId, workflowPathId){
            
            var nodeForm=document.getElementById("nodeForm");
            nodeForm.action="workflowAction-" + workflowId + "!removeFromNode.action?workflowNodeId=" + workflowNodeId + "&workflowPathId=" + workflowPathId;
            nodeForm.submit();
            return true;
        }
        
        function removeNextNode(workflowId, workflowNodeId, workflowPathId){
           
            var nodeForm=document.getElementById("nodeForm");
            nodeForm.action="workflowAction-" + workflowId + "!removeNextNode.action?workflowNodeId=" + workflowNodeId + "&workflowPathId=" + workflowPathId;
            nodeForm.submit();
            return true;
        }
        
        function addParticipant(workflowId, workflowNodeId){
            
            var nodeForm=document.getElementById("nodeForm");
            nodeForm.action="workflowAction-" + workflowId + "!addParticipant.action?workflowNodeId=" + workflowNodeId;
            nodeForm.submit();
            return true;
        }
        
        function removeParticipant(workflowId, workflowNodeId, participantId){
            
            var nodeForm=document.getElementById("nodeForm");
            nodeForm.action="workflowAction-" + workflowId + "!removeParticipant.action?workflowNodeId=" + workflowNodeId + "&participantId=" + participantId;
            nodeForm.submit();
            return true;
        }
        
        function addNodeContext(workflowId, workflowNodeId){
            
            var nodeForm=document.getElementById("nodeForm");
            nodeForm.action="workflowAction-" + workflowId + "!addNodeContext.action?workflowNodeId=" + workflowNodeId;
            nodeForm.submit();
            return true;
        }
        
        function removeNodeContext(workflowId, workflowNodeId, nodeContextId){
            
            var nodeForm=document.getElementById("nodeForm");
            nodeForm.action="workflowAction-" + workflowId + "!removeNodeContext.action?workflowNodeId=" + workflowNodeId + "&nodeContextId=" + nodeContextId;
            nodeForm.submit();
            return true;
        }
        function doNodeAttachmentDelete(){
            
            var nodeForm=document.getElementById("nodeForm");
            nodeForm.action="workflowAction!deleteNodeAttachment.action";
            nodeForm.submit();
            return true;
        }
		function validateNodeUpload(){
            var check=document.getElementsByName("selectedIds");
            var count = 0;
            for(var i=0;i <check.length;i++){
                if(check[i].checked==true){
                    count ++;
                }
            }
            if(count == 1){
                return true;
            }else{
                alert("只能选择一项");
                return false;
            }
        }
        function doNodeUpload(){
            var searchForm=document.getElementById("nodeForm");
            searchForm.action='workflowAction!toNodeUpload.action';
            searchForm.submit();
            return true;
        }
    //-->
    </script>
	</head>


	<body>
		<div id="div_title">
			<h3>
				工作流<s:label name="workflow.name"/>节点  <s:label name="workflowNode.name"/>
			</h3>
		</div>

		<!-- Data Form -->
		<%@include file="/white/common/message.jsp"%>
		<s:form method="post" id="nodeForm" name="nodeForm"  action="workflowAction!updateNode" theme="simple">
			<s:token />
			<s:hidden name="workId" value="%{workflow.workflowId}"></s:hidden>
			<s:hidden name="workNodeId" value="%{workflowNode.workflowNodeId}"></s:hidden>
			<table cellpadding="0" cellspacing="0" class="t_form">
				
				<tr>
					<td width="15%">
						节点名称:
					</td>
					<td>
						<s:textfield name="workflowNode.name" maxlength="15" />
						<span class="red_star">*</span>
					</td>
				</tr>
				<tr>
				<td width="15%">
						显示名称:
					</td>
					<td>
						<s:textfield name="workflowNode.displayName" maxlength="15" />
						<span class="red_star">*</span>
					</td>
				</tr>
				<tr>
					<td width="15%">
						类型:
					</td>
					<td>
						<s:select list="workflowNodeWorkTypeMap" headerKey=""
							headerValue="--请选择节点--" name="workflowNode.type"
							id="workflowNode.type"></s:select>
						<span class="red_star">*</span>
					</td>
				</tr>
				
			</table>

			<div id="div_button">

				<s:submit key="保存" action="workflowAction!updateNode"
					cssClass="input_button" />
				<s:submit key="返回"
					onclick="form.action='workflowAction-%{workflow.workflowId}!showDetail.action';return true;"
					cssClass="input_button" />
			</div>
			
			<table>
			  <tr>
			    <td>
			
			<br />
			<h3>
				前置节点:
			</h3>
			
						&nbsp;&nbsp;&nbsp;&nbsp;选择节点:
					
						<s:select list="nodeList" listKey="WORKFLOW_NODE_ID"
							listValue="DISPLAY_NAME" headerKey="" headerValue="=== 请选择 ==="
							name="preWorkflowNodeId" id="preWorkflowNodeId">
						</s:select>	
										
						&nbsp;&nbsp;路径名称:					
						<s:textfield name="fromPathName" maxlength="15" />	
						<a  href="javascript:addFromNode('${workflow.workflowId}','${workflowNode.workflowNodeId}')" >
											<img alt="新增" src="wf/images/New.png" width="15"
												height="15" /></a>					
					<br />
						<!--列表 -->
						<table cellpadding="0" cellspacing="0" class="t_list">
							<tr>								
								<!--列表头部 -->
								<th>
									名称
								</th>								
								<th>
									路径名称
								</th>								
								<th>
									设置
								</th>

							</tr>
							<s:iterator value="fromNodeList" status="sindex">
								<tr>									
									<td>
										<s:property value="NODE_NAME" />
									</td>									
									<td>
										<s:property value="PATH_DISPLAY_NAME" />
									</td>									
									<td>
										<a  href="javascript:removeFromNode('${workflow.workflowId}','${workflowNode.workflowNodeId}','${WORKFLOW_PATH_ID}')" >
											<img alt="设置" src="wf/images/Delete.png" width="15"
												height="15" /></a>
									</td>
								</tr>
							</s:iterator>
						</table>
						<!--列表结束-->
					
			</td>
			<td>
			&nbsp;&nbsp;
			</td>
			<td>
			    	
			<h3>
				后置节点:
			</h3>
			
						&nbsp;&nbsp;&nbsp;&nbsp;选择节点:
					
						<s:select list="nodeList" listKey="WORKFLOW_NODE_ID"
							listValue="DISPLAY_NAME" headerKey="" headerValue="=== 请选择 ==="
							name="afterWorkflowNodeId" id="afterWorkflowNodeId">
						</s:select>
					
						&nbsp;&nbsp;路径名称:
					
						<s:textfield name="nextPathName" maxlength="15" />
						<a  href="javascript:addNextNode('${workflow.workflowId}','${workflowNode.workflowNodeId}')" >
							<img alt="新增" src="wf/images/New.png" width="15"
								height="15" /></a>
					<br />
						<!--列表 -->
						<table cellpadding="0" cellspacing="0" class="t_list">
							<tr>								
								<!--列表头部 -->
								<th>
									名称
								</th>
								<th>
									路径名称
								</th>								
								<th>
									设置
								</th>

							</tr>
							<s:iterator value="nextNodeList" status="sindex">
								<tr>									
									<td>
										<s:property value="NODE_NAME" />
									</td>									
									<td>
										<s:property value="PATH_DISPLAY_NAME" />
									</td>								
									<td>
										<a  href="javascript:removeNextNode('${workflow.workflowId}','${workflowNode.workflowNodeId}','${WORKFLOW_PATH_ID}')" >
											<img alt="删除" src="wf/images/Delete.png" width="15"
												height="15" /></a>
									</td>
								</tr>
							</s:iterator>
						</table>
						<!--列表结束-->
					
			</td>
			  </tr>
			</table>
			
			<br />
			<table>
			  <tr>
			    <td>
			    
			<br />
			<h3>
				参与者:
			</h3>
			
						&nbsp;&nbsp;&nbsp;&nbsp;类型:
					
						<s:select list="participantTypeList" listKey="PARTICIPANT_TYPE"
							listValue="PARTICIPANT_TYPE_NAME" headerKey="" headerValue="=== 请选择 ==="
							name="participantType" id="participantType">
						</s:select>
					
						&nbsp;&nbsp;参与者:
					
						<s:textfield name="participantValue" maxlength="100" />
						<a  href="javascript:addParticipant('${workflow.workflowId}','${workflowNode.workflowNodeId}')" >
							<img alt="新增" src="wf/images/New.png" width="15"
								height="15" /></a>
					<br />
						<!--列表 -->
						<table cellpadding="0" cellspacing="0" class="t_list">
							<tr>								
								<!--列表头部 -->
								<th>
									名称
								</th>
								<th>
									类型
								</th>								
								<th>
									值
								</th>
								<th>
									操作
								</th>

							</tr>
							<s:iterator value="participantList" status="sindex">
								<tr>									
									<td>
										<s:property value="PARTICIPANT_NAME" />
									</td>									
									<td>
										<s:property value="PARTICIPANT_TYPE" />
									</td>
									<td>
										<s:property value="PARTICIPANT_VALUE" />
									</td>								
									<td>
										<a  href="javascript:removeParticipant('${workflow.workflowId}','${workflowNode.workflowNodeId}','${PARTICIPANTS_ID}')" >
											<img alt="删除" src="wf/images/Delete.png" width="15"
												height="15" /></a>
									</td>
								</tr>
							</s:iterator>
						</table>
						<!--列表结束-->
			
			</td>
			<td>
			&nbsp;&nbsp;
			</td>
			<td>
						
			<h3>
				参数设置
			</h3>
			&nbsp;&nbsp;&nbsp;&nbsp;类型:
					
						<s:select list="participantTypeList" listKey="PARTICIPANT_TYPE_NAME"
							listValue="PARTICIPANT_TYPE" headerKey="" headerValue="=== 请选择 ==="
							name="nodeParamType" id="nodeParamType">
						</s:select>
					
						&nbsp;&nbsp;名称:					
						<s:textfield name="nodeParamName" maxlength="100" />
						&nbsp;&nbsp;默认值:					
						<s:textfield name="nodeParamDefaultValue" maxlength="100" />
						<a  href="javascript:addNodeContext('${workflow.workflowId}','${workflowNode.workflowNodeId}')" >
							<img alt="新增" src="wf/images/New.png" width="15"
								height="15" /></a>
								<br />
			<!--列表 -->
			<table cellpadding="0" cellspacing="0" class="t_list">
				<tr>					
					<!--列表头部 -->
					<th>
						名称
					</th>
					<th>
						类型
					</th>
					<th>
						默认值
					</th>
					<th>
						设置
					</th>				

				</tr>
				<s:iterator value="nodeContextList" status="sindex">
					<tr>						
						<td>
							<s:property value="PARAM_NAME" />
						</td>
						<td>
							<s:property value="PARAM_TYPE" />
						</td>
						<td>
							<s:property value="DEFAULT_VALUE" />
						</td>
						<td>
							<a
								href="javascript:removeNodeContext('${workflow.workflowId}','${workflowNode.workflowNodeId}','${NODE_CONTEXT_ID}')">
								<img alt="删除" src="wf/images/Delete.png" width="15" height="15" /></a>
						</td>
					</tr>
				</s:iterator>
			</table>
			<!--列表结束-->		
			
			</td>
			  </tr>
			</table>
			<h3>
				节点附件设置
			</h3>
			
			<div id="div_button">
				<authz:authorize ifAnyGranted="SMOOTH_ALL">
					<s:submit value="新增"
						onclick="form.action='workflowAction!toAddNodeAttachment.action';return true;"
						cssClass="input_button" />
				</authz:authorize>				
				<authz:authorize ifAnyGranted="SMOOTH_ALL">
					<input type="button" value="删除"
						onclick="if(validateDelete()){doNodeAttachmentDelete()}" class="input_button">
				</authz:authorize>
				<authz:authorize ifAnyGranted="SMOOTH_ALL">
					<input type="button" value="添加附件"
						onclick="if(validateNodeUpload()){doNodeUpload()}" class="input_button"/>
				</authz:authorize>	
				<%@include file="/white/common/message.jsp"%>
			</div>
			<!--列表 -->
			<table cellpadding="0" cellspacing="0" class="t_list">
				<tr>
				<!--列表头部 -->
					<th>
						<input type="checkbox" onclick="selectCheckbox();"
							name="checkbox2" value="checkbox" />
					</th>
					<th>
						名称
					</th>
					<th>
						类型
					</th>
					<th>
						描述
					</th>
					<th>
						附件
					</th>		
				</tr>
				<s:iterator value="nodeAttachmentList" status="sindex">
					<tr>
						<td>
							<input type="checkbox" name="selectedIds"
								value="${NODE_ATTACHMENT_ID}" id="selectedIds" />
						</td>
						<td>
							<s:property value="NAME" />
						</td>
						<td>
							<s:property value="TYPE" />
						</td>
						<td>
							<s:property value="DESCRIPTION" />
						</td>
						<td>
							<a href="<s:url value='download.action'>                  
                    				<s:param name='fileName'  
 									value='RESOURCE_ID'/>     
                 					</s:url>">
                 			<s:property value="FNAME" />
                 			</a>
						</td>
					</tr>
				</s:iterator>
			</table>
			<!--列表结束-->
		</s:form>
		<!--Data Form End -->

	</body>

</html>